import {Entity} from "../../entity";
import {Alias, Column, Editor, Serialize} from "../../decorator";

export enum ModuleType {
    System = 0,
    Module = 1
}

//模块权限（M表）
export class Module extends Entity{

    @Editor("String")
    @Alias("模块名称")
    @Serialize("name")
    public name: string = "";

    @Editor("String")
    @Alias("模块编码")
    @Serialize("code")
    public code: string = "";

    @Editor("Memo")
    @Alias("模块描述")
    @Serialize("description")
    public description: string = "";

    @Editor("Number")
    @Alias("模块级别")
    @Serialize("type")
    public type: number = ModuleType.System;

    @Editor("String")
    @Alias("模块路由")
    @Serialize("route")
    public route: string = "";

    @Editor("Number")
    @Alias("排列顺序")
    @Serialize("order")
    public order: number = 0;

    @Serialize("root")
    public root: any = null;

    @Serialize("parent")
    public parent: any = null;

    public expand: boolean;
    public checked: boolean;

    public children: any = [];

    constructor() {
        super();
    }

    fromJSON(obj) {
        super.fromJSON(obj);
    }

    getChildren(modules){
        this.children = modules.filter(item => item.parent && item.parent._id === this._id);
    }
}


